package 代码记录.指定公司代码练习记录.华为_2024.分值100.第36start;

import java.util.*;

/**
 * @author zx
 * @create 2024-02-16 13:13
 * 看懂人家的代码了，二刷要自己能做出来
 */
public class 跳房子I_47 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        str = str.substring(1,str.length() - 1);
        int target = sc.nextInt();
        String[] nums = str.split(",");
        int[] arr = new int[nums.length];
        for(int i = 0;i < arr.length;i++){
            arr[i] = Integer.parseInt(nums[i]);
        }
        int minIdSum = Integer.MAX_VALUE;
        HashMap<Integer, Integer> map = new HashMap<>();//用于存储整数和其索引的映射关系
        int[] res = new int[2];
        for (int i = 0; i < arr.length; i++) {
            int temp = target - arr[i];//两数之和
            if (map.containsKey(temp)) {//数组中的元素不能重复使用
                //更新最小索引和(minIdSum)和结果数组(res)
                if (minIdSum > map.get(temp) + i) {
                    minIdSum = map.get(temp) + i;
                    res[0] = temp;
                    res[1] = arr[i];
                }
            }
            if (!map.containsKey(arr[i])) {
                map.put(arr[i], i);
            }
        }
        System.out.println(Arrays.toString(res));
    }
}
